from .models import CMSPermission
from flask import session, g
from .models import CMSUser
import config
from .views import bp


@bp.before_app_request
def before_request():
    if config.CMS_USER_ID in session:
        user_id = session.get(config.CMS_USER_ID)
        user = CMSUser.query.get(user_id)
        if user:
            g.cms_user = user


# 上下文处理器，这个参数所有页面都可以使用
@bp.context_processor
def cms_context_processor():
    return {'CMSPermission': CMSPermission}
